package org.topteam.ui.easyui;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import java.util.Map;

/**
 * Created by JiangFeng on 2014/8/7.
 */
public class EventListenerTag extends TagRender {
    private String forId;
    private String event;
    private String listener;

    @Override
    public String getEasyuiTag() {
        return null;
    }

    @Override
    public int renderBody() {
        return SKIP_BODY;
    }

    @Override
    public Map<String, Object> getOptions() {
        return null;
    }

    @Override
    public void renderStart(JspWriter out) {

    }

    @Override
    public void renderEnd(JspWriter out) {
        getRenderContext().putEvent(this);
    }

    @Override
    public int doStartTag() throws JspException {
//        JspWriter out = this.pageContext.getOut();
//        Object tag = this.pageContext.getRequest().getAttribute(getFor());
//        if (getFor() != null && tag != null) {
//            ScriptWriter sw = new ScriptWriter();
//            if(tag.toString().equals(ButtonTag.TAG)){
//                sw.write("$('#" + getFor() + "').bind('" + getEvent() + "',function(){"+getListener()+".apply(arguments);});");
//            }else{
//                sw.write("$('#" + getFor() + "')." + tag.toString() + "({" + getEvent() + ":function(){"+getListener()+".apply(arguments);}});");
//            }
//            try {
//                out.write(sw.toString());
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
        return SKIP_BODY;
    }

    public String getEvent() {
        return event;
    }

    public void setEvent(String event) {
        this.event = event;
    }

    public String getListener() {
        return listener;
    }

    public void setListener(String listener) {
        this.listener = listener;
    }

    public String getFor() {
        return forId;
    }

    public void setFor(String forId) {
        this.forId = forId;
    }
}
